﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace ADC.Utilites
{
    public class Common
    {
        public const string PAGE_TITLE = "Dien may ADC- ";
        public const string UPDATE_FAIL = "Update fail";
        public const string UPDATE_SUCESSFULLY = "Update sucessfully";
        public const string INSERT_FAIL = "Tạo mới lỗi";
        public const string INSERT_SUCESSFULLY = "Insert sucessfully";
        public const string IMAGE_PROGRAME_PATH = "Images/ProgrameGallery/";
        public const string IMAGE_PROJECT_PATH = "Images/Project/";
        public const string IMAGE_PROJECT_PATH_TYPE = "Images/ProjectType/";
        public const string IMAGE_CONSULTING_PATH = "Images/consulting/";
        public const string IMAGE_PROMOTION_PATH = "Images/promotion/";
        public const string IMAGE_RECRUITMENT_PATH = "Images/recruitment/";
        public const string IMAGE_PRODUCT = "Images/Product/";

        public const string IMAGE_BANNER_GALLERY_PATH = "Images/BannerGallery/";
        public const string PDF_OF_CRUISE_PATH = "Images/PdfOfCruise/";
        public const string IMAGE_UPLOAD = "Images/Upload/";

        public static string EncodePassword(string originalPassword)
        {
            //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] originalBytes = Encoding.Default.GetBytes(originalPassword);
            byte[] encodedBytes = md5.ComputeHash(originalBytes);

            //Convert encoded bytes back to a 'readable' string
            return BitConverter.ToString(encodedBytes);
        }

        public static string ReadXMLFormat(string filename)
        {
            string strReaded = "";
            try
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        strReaded = strReaded + line + "\r\n";
                    }
                    sr.Close();
                }
            }
            catch
            {
                return "<b><font color=#FF0000>Error: File not found \"" + filename + "\"</font></b>";
            }
            return strReaded;
        }

        public static bool WriteXML(string filename, string data)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(filename))
                {
                    sw.WriteLine(data);
                    sw.Close();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }



    }
}
